package com.aaa.tomcat;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.IOException;
import java.io.OutputStream;

/**
 * @author ：Teacher陈
 * @date ：Created in 2021/1/20 10:35
 * @description：自创响应类
 * @modified By：
 * @version: 1
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseAAA {
    private OutputStream outputStream;
    /**
     * @create by: Teacher陈
     * @description:将内容写回浏览器
     * @create time: 2021/1/20 10:37
     * @param context
     * @return void
     */
    public void write(String context) throws IOException {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("HTTP/1.1 200\r\n");
        stringBuffer.append("Content-Type: text/html\r\n");
        stringBuffer.append("\r\n");
        stringBuffer.append("<html>");
        stringBuffer.append("<body>");
        stringBuffer.append(context);
        stringBuffer.append("</body>");
        stringBuffer.append("</html>");
        outputStream.write(stringBuffer.toString().getBytes());
        outputStream.flush();
        outputStream.close();
    }


}
